<!DOCTYPE html>
<html lang=en>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000" />
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top" />
  
  
  <title>ROS Guidance | 鲨鱼之家</title>
  <meta name="description" content="0. Example 1. Initialize Workspace and Create Package  1.1. Initialize Workspace 1.2. Compile 1.3. Set Path   2. Create Packages 3. Create car.msg 4. Set package.xml 5. Set CMakeLists.txt 6. Publish">
<meta property="og:type" content="article">
<meta property="og:title" content="ROS Guidance">
<meta property="og:url" content="http://tina-yao.gitee.io/bigbig-shark/2022/07/12/ROS-Guidance/index.html">
<meta property="og:site_name" content="大鲨鱼">
<meta property="og:description" content="0. Example 1. Initialize Workspace and Create Package  1.1. Initialize Workspace 1.2. Compile 1.3. Set Path   2. Create Packages 3. Create car.msg 4. Set package.xml 5. Set CMakeLists.txt 6. Publish">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713010030158.png">
<meta property="og:image" content="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713010354620.png">
<meta property="og:image" content="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713010555816.png">
<meta property="og:image" content="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713010742372.png">
<meta property="og:image" content="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713011103262.png">
<meta property="og:image" content="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713011433931.png">
<meta property="og:image" content="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713012706770.png">
<meta property="og:image" content="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713012735289.png">
<meta property="og:image" content="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713012811097.png">
<meta property="og:image" content="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713012833979.png">
<meta property="og:image" content="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713020045754.png">
<meta property="og:image" content="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/Screenshot%20from%202022-07-13%2000-35-45.png">
<meta property="article:published_time" content="2022-07-12T10:10:43.000Z">
<meta property="article:modified_time" content="2022-07-27T11:57:12.618Z">
<meta property="article:author" content="BigbigShark">
<meta property="article:tag" content="ROS">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713010030158.png">
  <!-- Canonical links -->
  <link rel="canonical" href="http://tina-yao.gitee.io/bigbig-shark/2022/07/12/ROS-Guidance/index.html">
  
    <link rel="alternate" href="/atom.xml" title="大鲨鱼" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png" type="image/x-icon">
  
  
<link rel="stylesheet" href="/bigbig-shark/css/style.css">

  
  
  
  
<meta name="generator" content="Hexo 5.4.0"></head>


<body class="main-center theme-purple# 主题颜色 theme-black theme-blue theme-green theme-purple" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="https://tina-yao.gitee.io/bigbig-shark/" target="_blank">
          <img class="img-circle img-rotate" src="/bigbig-shark/images/avatar.jpg" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">大鲨鱼</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">CV&amp;Robots</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> Wuhan, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="Search" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="Type something..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav menu-highlight">
        
        
        <li class="menu-item menu-item-home">
          <a href="/bigbig-shark/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">Home</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/bigbig-shark/archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">Archives</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/bigbig-shark/categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">Categories</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/bigbig-shark/tags">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">Tags</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-links">
          <a href="/bigbig-shark/links">
            
            <i class="icon icon-friendship"></i>
            
            <span class="menu-title">Links</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-about">
          <a href="/bigbig-shark/about">
            
            <i class="icon icon-cup-fill"></i>
            
            <span class="menu-title">About</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="https://gitee.com/tina-yao" target="_blank" title="Gitee" data-toggle=tooltip data-placement=top><i class="icon icon-gitee"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">Board</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>欢迎交流与分享经验!</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">Categories</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/bigbig-shark/categories/AI/">AI</a><span class="category-list-count">1</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/bigbig-shark/categories/AI/ML/">ML</a><span class="category-list-count">1</span></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/bigbig-shark/categories/Concepts/">Concepts</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/bigbig-shark/categories/Robots/">Robots</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/bigbig-shark/categories/%E5%8D%8A%E6%97%A5%E9%97%B2/">半日闲</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/bigbig-shark/categories/%E6%95%B0%E5%AD%A6%E5%BB%BA%E6%A8%A1/">数学建模</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/bigbig-shark/categories/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/">数据分析</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/bigbig-shark/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA%E8%A7%86%E8%A7%89/">计算机视觉</a><span class="category-list-count">30</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget-body tagcloud">
      <a href="/bigbig-shark/tags/CNN-backbones/" style="font-size: 13.67px;">CNN_backbones</a> <a href="/bigbig-shark/tags/OpenCV/" style="font-size: 13px;">OpenCV</a> <a href="/bigbig-shark/tags/Python/" style="font-size: 13px;">Python</a> <a href="/bigbig-shark/tags/ROS/" style="font-size: 13px;">ROS</a> <a href="/bigbig-shark/tags/%E4%BB%A3%E7%A0%81/" style="font-size: 13px;">代码</a> <a href="/bigbig-shark/tags/%E5%85%83%E5%AE%87%E5%AE%99/" style="font-size: 13px;">元宇宙</a> <a href="/bigbig-shark/tags/%E5%85%B4%E8%B6%A3/" style="font-size: 13px;">兴趣</a> <a href="/bigbig-shark/tags/%E5%9C%BA%E6%99%AF%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB/" style="font-size: 13px;">场景文字识别</a> <a href="/bigbig-shark/tags/%E6%91%98%E6%8A%84/" style="font-size: 13.33px;">摘抄</a> <a href="/bigbig-shark/tags/%E6%95%B0%E6%8D%AE%E9%9B%86/" style="font-size: 13px;">数据集</a> <a href="/bigbig-shark/tags/%E7%9B%AE%E6%A0%87%E6%A3%80%E6%B5%8B/" style="font-size: 14px;">目标检测</a> <a href="/bigbig-shark/tags/%E7%BE%8E%E8%B5%9B/" style="font-size: 13px;">美赛</a> <a href="/bigbig-shark/tags/%E8%81%9A%E7%B1%BB/" style="font-size: 13px;">聚类</a> <a href="/bigbig-shark/tags/%E8%87%AA%E5%8A%A8%E9%A9%BE%E9%A9%B6/" style="font-size: 13.33px;">自动驾驶</a> <a href="/bigbig-shark/tags/%E8%AE%A1%E7%AE%97%E6%9C%BA%E8%A7%86%E8%A7%893D/" style="font-size: 13px;">计算机视觉3D</a> <a href="/bigbig-shark/tags/%E8%BD%BB%E9%87%8F%E7%BA%A7/" style="font-size: 13px;">轻量级</a>
    </div>
  </div>

    
  </div>
</aside>

  
  
<main class="main" role="main">
  <div class="content">
  <article id="post-ROS-Guidance" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      ROS Guidance
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/bigbig-shark/2022/07/12/ROS-Guidance/" class="article-date">
	  <time datetime="2022-07-12T10:10:43.000Z" itemprop="datePublished">2022-07-12</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/bigbig-shark/categories/Robots/">Robots</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link-link" href="/bigbig-shark/tags/ROS/" rel="tag">ROS</a>
  </span>


        

	<span class="article-read hidden-xs">
    	<i class="icon icon-eye-fill" aria-hidden="true"></i>
    	<span id="/bigbig-shark/2022/07/12/ROS-Guidance/" class="leancloud_visitors"  data-flag-title="ROS Guidance">
			<span class="leancloud-visitors-count">0</span>
		</span>
    </span>

        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/bigbig-shark/2022/07/12/ROS-Guidance/#comments" class="article-comment-link">Comments</a></span>
        
	
		<span class="post-wordcount hidden-xs" itemprop="wordCount">Word Count: 398(words)</span>
	
	
		<span class="post-readcount hidden-xs" itemprop="timeRequired">Read Count: 2(minutes)</span>
	

      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <!-- toc -->
<ul>
<li><a href="#0-example">0. Example</a></li>
<li><a href="#1-initialize-workspace-and-create-package">1. Initialize Workspace and Create Package</a>
<ul>
<li><a href="#11-initialize-workspace">1.1. Initialize Workspace</a></li>
<li><a href="#12-compile">1.2. Compile</a></li>
<li><a href="#13-set-path">1.3. Set Path</a></li>
</ul>
</li>
<li><a href="#2-create-packages">2. Create Packages</a></li>
<li><a href="#3-create-carmsg">3. Create car.msg</a></li>
<li><a href="#4-set-packagexml">4. Set package.xml</a></li>
<li><a href="#5-set-cmakeliststxt">5. Set CMakeLists.txt</a></li>
<li><a href="#6-publisher">6. Publisher</a></li>
<li><a href="#7-subcriber">7. Subcriber</a></li>
<li><a href="#8-execute">8. Execute</a></li>
</ul>
<!-- tocstop -->
<h2><span id="0-example">0. Example</span></h2>
<p><img src="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713010030158.png" alt="image-20220713010030158"></p>
<h2><span id="1-initialize-workspace-and-create-package">1. Initialize Workspace and Create Package</span></h2>
<h3><span id="11-initialize-workspace">1.1.  Initialize Workspace</span></h3>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">mkdir -p ~/test_ws/src <span class="comment"># the last must be src</span></span><br><span class="line">cd ~/test_ws/src <span class="comment"># enter the src</span></span><br><span class="line">catkin_init_workspace <span class="comment"># initialize the workspace # generate CMakeLists</span></span><br></pre></td></tr></table></figure>
<p><img src="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713010354620.png" alt="image-20220713010354620"></p>
<h3><span id="12-compile">1.2. Compile</span></h3>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd ..</span><br><span class="line">catkin_make </span><br><span class="line">catkin_make install</span><br></pre></td></tr></table></figure>
<p><img src="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713010555816.png" alt="image-20220713010555816"></p>
<h3><span id="13-set-path">1.3. Set Path</span></h3>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">source ~/test_ws/devel/setup.bash <span class="comment"># every time you compile, you must do this</span></span><br><span class="line"><span class="comment">##===== or add it directly into .bashrc, once and for ever =====##</span></span><br><span class="line"><span class="comment">## tips: use Ctrl + H to find the .bashrc in the home dir</span></span><br></pre></td></tr></table></figure>
<p><img src="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713010742372.png" alt="image-20220713010742372"></p>
<h2><span id="2-create-packages">2. Create Packages</span></h2>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd src</span><br><span class="line">catkin_create_pkg learning_car roscpp rospy std_msgs</span><br></pre></td></tr></table></figure>
<p><img src="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713011103262.png" alt="image-20220713011103262"></p>
<h2><span id="3-create-carmsg">3. Create car.msg</span></h2>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">cd learning_car</span><br><span class="line">mkdir msg</span><br><span class="line">cd msg</span><br><span class="line">touch car.msg</span><br><span class="line">vim car.msg </span><br><span class="line"><span class="comment"># edit the content</span></span><br></pre></td></tr></table></figure>
<p><img src="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713011433931.png" alt="image-20220713011433931"></p>
<h2><span id="4-set-packagexml">4. Set package.xml</span></h2>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&lt;build_depend&gt;message_generation&lt;/build_depend&gt;</span><br><span class="line">&lt;exec_depend&gt;message_runtime&lt;/exec_depend&gt;</span><br></pre></td></tr></table></figure>
<p><img src="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713012706770.png" alt="image-20220713012706770"></p>
<h2><span id="5-set-cmakeliststxt">5. Set CMakeLists.txt</span></h2>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">find_package(... message_generation)</span><br><span class="line"></span><br><span class="line">add_message_files(FILES car.msg)</span><br><span class="line">generate_messages(DEPENDENCIES std_msgs)</span><br><span class="line"></span><br><span class="line">catkin_package(... message_runtime)</span><br></pre></td></tr></table></figure>
<p><img src="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713012735289.png" alt="image-20220713012735289"></p>
<p><img src="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713012811097.png" alt="image-20220713012811097"></p>
<p><img src="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713012833979.png" alt="image-20220713012833979"></p>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># compile</span></span><br><span class="line">cd ~/test_ws</span><br><span class="line">catkin_make</span><br></pre></td></tr></table></figure>
<p><img src="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/image-20220713020045754.png" alt="image-20220713020045754"></p>
<h2><span id="6-publisher">6. Publisher</span></h2>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//car_publisher.cpp</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;ros/ros.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&quot;learning_car/car.h&quot;</span></span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">int</span> argc, <span class="keyword">char</span> **argv)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">//init node</span></span><br><span class="line">    ros::<span class="built_in">init</span>(argc, argv, <span class="string">&quot;car_publisher&quot;</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">//create nodehandle</span></span><br><span class="line">    ros::NodeHandle n;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//create a publisher, publishing a topic named car_msg</span></span><br><span class="line">    ros::Publisher car_pub = n.advertise&lt;learning_car::car&gt;(<span class="string">&quot;/car_msg&quot;</span>, <span class="number">10</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">//set the loop frequency</span></span><br><span class="line">    <span class="function">ros::Rate <span class="title">loop_rate</span><span class="params">(<span class="number">10</span>)</span></span>;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">int</span> count = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">while</span>(ros::<span class="built_in">ok</span>())&#123;</span><br><span class="line">        <span class="comment">//init the message of type geometry_msg::Twist</span></span><br><span class="line">        learning_car::car car_info;</span><br><span class="line">        car_info.id = <span class="number">1</span>;</span><br><span class="line">        car_info.color = <span class="number">255</span>;</span><br><span class="line">        car_info.pose = <span class="number">127</span>;</span><br><span class="line">        car_info.x = <span class="number">45</span>;</span><br><span class="line">        car_info.y = <span class="number">50</span>;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//publish</span></span><br><span class="line">        car_pub.<span class="built_in">publish</span>(car_info);</span><br><span class="line">        <span class="built_in">ROS_INFO</span>(<span class="string">&quot;Publish car_msg: [id: %d, color: %d, pose: %d, x: %.4f, y: %.4f]&quot;</span>, car_info.id, car_info.color, car_info.pose, car_info.x, car_info.y);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//sleep</span></span><br><span class="line">        loop_rate.<span class="built_in">sleep</span>();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2><span id="7-subcriber">7. Subcriber</span></h2>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/env python</span></span><br><span class="line"><span class="comment"># car_subscriber.py</span></span><br><span class="line"><span class="keyword">import</span> rospy</span><br><span class="line"><span class="keyword">from</span> learning_car.msg <span class="keyword">import</span> car</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">carInfoCallBack</span>(<span class="params">ms</span>):</span></span><br><span class="line">    rospy.loginfo(<span class="string">&quot;Subscribe car_msg: [id: %d, color: %d, pose: %d, x: %.4f, y: %.4f]&quot;</span>, ms.<span class="built_in">id</span>, ms.color, ms.pose, ms.x, ms.y)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">car_subscriber</span>():</span></span><br><span class="line">    <span class="comment">#init node</span></span><br><span class="line">    rospy.init_node(<span class="string">&#x27;car_subscriber&#x27;</span>, anonymous=<span class="literal">True</span>)</span><br><span class="line"></span><br><span class="line">    <span class="comment"># create a subscriber subscribing a topic named car_msg</span></span><br><span class="line">    rospy.Subscriber(<span class="string">&quot;/car_msg&quot;</span>, car, carInfoCallBack)</span><br><span class="line"></span><br><span class="line">    <span class="comment"># loop</span></span><br><span class="line">    rospy.spin()</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    car_subscriber()</span><br></pre></td></tr></table></figure>
<h2><span id="8-execute">8. Execute</span></h2>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">roscore</span><br><span class="line">rosrun learning_car car_subscriber.py</span><br><span class="line">rosrun learning_car car_publisher</span><br></pre></td></tr></table></figure>
<p><img src="https://gitee.com/tina-yao/bigbig-shark/raw/master/imgs/ROS%20Guidance.assets/Screenshot%20from%202022-07-13%2000-35-45.png" alt></p>

      
    </div>
    <div class="article-footer">
      <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="http://tina-yao.gitee.io/bigbig-shark/2022/07/12/ROS-Guidance/" title="ROS Guidance" target="_blank" rel="external">http://tina-yao.gitee.io/bigbig-shark/2022/07/12/ROS-Guidance/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://tina-yao.gitee.io/bigbig-shark/" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/bigbig-shark/images/avatar.jpg" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://tina-yao.gitee.io/bigbig-shark/" target="_blank"><span class="text-dark">大鲨鱼</span><small class="ml-1x">CV&amp;Robots</small></a></h3>
        <div>格物致知，诚意力行。</div>
      </div>
    </figure>
  </div>
</div>


    </div>
  </article>
  
    
  <section id="comments">
  	
      <div id="vcomments"></div>
    
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/bigbig-shark/2022/07/15/CNN-backbone-1-AlexNet/" title="CNN_backbone(1)_AlexNet"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;Newer</span></a>
    </li>
    
    
    <li class="next">
      <a href="/bigbig-shark/2022/04/20/%E7%B2%BE%E7%A1%AE%E8%AE%A1%E7%AE%97%E7%9A%84%E4%B8%A4%E4%B8%AA%E5%8F%91%E5%B1%95%E6%96%B9%E5%90%91/" title="精确计算的两个发展方向"><span>Older&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
  </ul>
  
  
  <!-- Button trigger modal -->
  <button type="button" class="btn btn-fancy btn-donate pop-onhover bg-gradient-warning" data-toggle="modal" data-target="#donateModal"><span>$</span></button>
  <!-- <div class="wave-icon wave-icon-danger btn-donate" data-toggle="modal" data-target="#donateModal">
    <div class="wave-circle"><span class="icon"><i class="icon icon-bill"></i></span></div>
  </div> -->
  
  
  <div class="bar-right">
    
    <div class="share-component" data-sites="weibo,qq,wechat" data-mobile-sites="weibo,qq"></div>
    
  </div>
  </div>
</nav>
  
<!-- Modal -->
<div class="modal modal-center modal-small modal-xs-full fade" id="donateModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content donate">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <div class="modal-body">
        <div class="donate-box">
          <div class="donate-head">
            <p>Maybe you could buy me a cup of coffee.</p>
          </div>
          <div class="tab-content">
            <div role="tabpanel" class="tab-pane fade active in" id="alipay">
              <div class="donate-payimg">
                <img src="https://gitee.com/tina-yao/bigbig-shark/raw/master/images/donate/alipayimg.PNG#images/donate/alipayimg.png" alt="Scan Qrcode" title="Scan" />
              </div>
              <p class="text-muted mv">Scan this qrcode</p>
              <p class="text-grey">Open alipay app scan this qrcode, buy me a coffee!</p>
            </div>
            <div role="tabpanel" class="tab-pane fade" id="wechatpay">
              <div class="donate-payimg">
                <img src="https://gitee.com/tina-yao/bigbig-shark/raw/master/images/donate/wechatpayimg.PNG#images/donate/wechatpayimg.png" alt="Scan Qrcode" title="Scan" />
              </div>
              <p class="text-muted mv">Scan this qrcode</p>
              <p class="text-grey">Open wechat app scan this qrcode, buy me a coffee!</p>
            </div>
          </div>
          <div class="donate-footer">
            <ul class="nav nav-tabs nav-justified" role="tablist">
              <li role="presentation" class="active">
                <a href="#alipay" id="alipay-tab" role="tab" data-toggle="tab" aria-controls="alipay" aria-expanded="true"><i class="icon icon-alipay"></i> alipay</a>
              </li>
              <li role="presentation" class="">
                <a href="#wechatpay" role="tab" id="wechatpay-tab" data-toggle="tab" aria-controls="wechatpay" aria-expanded="false"><i class="icon icon-wepay"></i> wechat payment</a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>



</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="https://gitee.com/tina-yao" target="_blank" title="Gitee" data-toggle=tooltip data-placement=top><i class="icon icon-gitee"></i></a></li>
        
    </ul>

    <div class="copyright">
    	
        &copy; 2023 BigbigShark
        
        <div class="publishby">
        <!--
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        -->
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>

<script src="/bigbig-shark/js/plugin.min.js"></script>


<script src="/bigbig-shark/js/application.js"></script>


    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: 'Posts',
            PAGES: 'Pages',
            CATEGORIES: 'Categories',
            TAGS: 'Tags',
            UNTITLED: '(Untitled)',
        },
        ROOT_URL: '/bigbig-shark/',
        CONTENT_URL: '/bigbig-shark/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/bigbig-shark/js/insight.js"></script>






   




   
    
  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/valine"></script>
  <script type="text/javascript">
  var GUEST = ['nick', 'mail', 'link'];
  var meta = 'nick,mail,link';
  meta = meta.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#vcomments',
    verify: false,
    notify: false,
    appId: '8pTCCvyyLGXskH0XW0fWHg7l-gzGzoHsz',
    appKey: 'id3rlCPRdbEoSpUfhJgcLhDO',
    placeholder: 'Just go go',
    avatar: 'mm',
    meta: meta,
    pageSize: '10' || 10,
    visitor: true
  });
  </script>

     







<script src="/bigbig-shark/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginModelPath":"assets/","model":{"jsonPath":"/bigbig-shark/live2dw/assets/tororo.model.json"},"display":{"position":null,"width":300,"height":600},"log":false,"pluginJsPath":"lib/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>